#if !SILVERLIGHT
using System.Web;
using System.Web.UI;
using System.Web.Hosting;
using System.Collections.Generic;
using SBPweb.Common.Configuration;

namespace SBPweb.Common.Session
{
    /// <summary>
    /// Summary description for ThemeManager
    /// </summary>
    public class ThemeManager
    {
		/// <summary>
		/// List of available themes
		/// </summary>
		/// <returns>list</returns>
        public static List<string> ListAvailableThemes()
        {
            List<string> ret = new List<string>();
            foreach (VirtualDirectory d in ConfigurationHandler.VirtualThemesDirectory.Directories)
            {
                ret.Add(d.Name);
            }

            return ret;
        }

		private const string KEY_SelectedThemeName = "_PreferredThemeName";

		/// <summary>
		/// currently selected theme
		/// </summary>
		public static string SelectedTheme
		{
			get
			{
				if (!SessionHandler.IsAvailable)
				{
					return CookieHandler.DefaultTheme;
				}
				string ret = SessionHandler.Get<string>(KEY_SelectedThemeName);
				if (string.IsNullOrEmpty(ret))
				{
					ret = CookieHandler.DefaultTheme;
					SessionHandler.Put<string>(KEY_SelectedThemeName, ret);
				}
				return ret;
			}
			set
			{
				if (!SessionHandler.IsAvailable)
				{
					return;
				}
				SessionHandler.Put<string>(KEY_SelectedThemeName, value);
				CookieHandler.DefaultTheme = value;
			}
		}

		/// <summary>
		/// Maintain the current theme
		/// </summary>
		/// <param name="page">page</param>
        public static void MaintainTheme(Page page)
        {
            if (page.Theme != ThemeManager.SelectedTheme)
            {
				//string s = ConfigurationHandler.VirtualRootDirectory.VirtualPath;

				//page.MasterPageFile = s + "xHTML/Masters/" + ThemeManager.SelectedTheme.Replace("xHTML.", "") + ".master";
                page.Theme = ThemeManager.SelectedTheme;
            }
        }
    }
}
#endif